<?php
    //require_once("./linguas/pt_br.php");
    require_once("./config.php");
    require_once("./classes/sessao.php");
    require_once("./classes/traducao.class.php");
    session_start();
    if (!isset($_SESSION['ANAWEB']) || $_SESSION['ANAWEB']->RetornaIdioma() == "PT_BR")
    {
        $msg = new Traducao($DOCUMENT_ROOT."/linguas/linguas.xml", "pt-br");
    }
    else
    {
        $msg = new Traducao($DOCUMENT_ROOT."/linguas/linguas.xml", "en-us");
    }
    if ($_SESSION['ANAWEB']->RetornaAmbiente() == "numerico")
    {
        if ($_SESSION['ANAWEB']->RetornaModo() == "aluno")
        {
?>
var TREE_ITEMS = [
    ['Na-Web', 'index.php',
        ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Aritmetica_PF')),ENT_QUOTES); ?>','javascript:trees[0].toggle(1)',
            ['<?php echo ( $msg->get('Menu_Sistema_PF') ); ?>','index.php?opcao=sistemaPF'],
            ['<?php echo ( $msg->get('Menu_Soma') ); ?>','index.php?opcao=somaPF'],
            ['<?php echo ( $msg->get('Menu_Subtracao') ); ?>','index.php?opcao=subtracaoPF'],
            ['<?php echo ( $msg->get('Menu_Multiplicacao') ); ?>','index.php?opcao=multiplicacaoPF'],
            ['<?php echo ( $msg->get('Menu_Divisao') ); ?>','index.php?opcao=divisaoPF']
        ],
        ['<?php echo ( $msg->get('Menu_Aritmetica_Matricial') ); ?>','javascript:trees[0].toggle(7)',
            ['<?php echo ( $msg->get('Menu_Soma') ); ?>','index.php?opcao=soma'],
            ['<?php echo ( $msg->get('Menu_Multiplicacao') ); ?>','index.php?opcao=multiplicacao'],
            ['<?php echo ( $msg->get('Menu_Transposta') ); ?>','index.php?opcao=transposta'],
            ['<?php echo ( $msg->get('Menu_Determinante') ); ?>','index.php?opcao=determinante'],
            ['<?php echo ( $msg->get('Menu_Inversa') ); ?>','index.php?opcao=inversa'],
            ['<?php echo ( $msg->get('Menu_Decomposicao') ); ?>','index.php?opcao=decmat'],
            ['<?php echo ( $msg->get('Menu_Matrizes_Definidas_Positivas') ); ?>','index.php?opcao=matdefpos']
        ],
        ['<?php echo ( $msg->get('Menu_SEAL') ); ?>','javascript:trees[0].toggle(15)',
            ['<?php echo ( $msg->get('Menu_Metodos_Diretos') ); ?>','javascript:trees[0].toggle(16)',
                ['<?php echo ( $msg->get('Menu_Eliminacao_Gauss') ); ?>','javascript:trees[0].toggle(17)',
                    ['<?php echo ( $msg->get('Menu_Sem_Pivoteamento') ); ?>','index.php?opcao=gauss1'],
                    ['<?php echo ( $msg->get('Menu_Pivoteamento_Parcial') ); ?>','index.php?opcao=gauss2'],
                    //['<?php //echo ( Menu_Pivoteamento_Total ); ?>','index.php?opcao=gauss3'],
                ],
                ['<?php echo ( $msg->get('Menu_Decomposicao_LU') ); ?>','index.php?opcao=ludecomp'],
                ['<?php echo ( $msg->get('Menu_Cholesky') ); ?>','index.php?opcao=cholesky'],
            ],
            ['<?php echo ( $msg->get('Menu_Metodos_Iterativos') ); ?>','javascript:trees[0].toggle(22)',
                ['<?php echo ( $msg->get('Menu_Jacobi') ); ?>','index.php?opcao=jacobi'],
                ['<?php echo ( $msg->get('Menu_Gauss_Seidel') ); ?>','index.php?opcao=gauss-seidel']
            ]
        ],
        ['<?php echo ( $msg->get('Menu_Interpolacao') ); ?>','javascript:trees[0].toggle(25)',
            ['<?php echo ( $msg->get('Menu_Lagrange') ); ?>','index.php?opcao=lagrange'],
            ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Newton')),ENT_QUOTES); ?>','index.php?opcao=newton'],
            ['<?php echo ( $msg->get('Menu_Splines') ); ?>','index.php?opcao=spline']
        ],
        ['<?php echo ( $msg->get('Menu_Ajuste_Dados') ); ?>','javascript:trees[0].toggle(29)',
            ['<?php echo ( $msg->get('Menu_Minimos_Quadrados') ); ?>','index.php?opcao=ajdados1'],
            ['<?php echo ( $msg->get('Menu_Minimos_Quadrados_Polinomios_Ortogonais') ) ; ?>','index.php?opcao=ajdados2']
        ],
        ['<?php echo ( $msg->get('Menu_EQNL') ); ?>','javascript:trees[0].toggle(32)',
            ['<?php echo ( $msg->get('Menu_Bisseccao') ); ?>','index.php?opcao=eqnl2'],
            ['<?php echo ( $msg->get('Menu_Secante') ); ?>','index.php?opcao=eqnl1'],
            ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Newton_EQNL')),ENT_QUOTES); ?>','index.php?opcao=eqnl3']
        ],
        ['<?php echo ( $msg->get('Menu_SEANL') ); ?>','javascript:trees[0].toggle(36)',
            ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Newton_SEANL')),ENT_QUOTES);; ?>','index.php?opcao=seqnl']
        ],
        ['<?php echo ( $msg->get('Menu_Integrais_Derivadas') ); ?>','javascript:trees[0].toggle(38)',
            ['<?php echo ( $msg->get('Menu_Derivacao') ); ?>','javascript:trees[0].toggle(39)',
                ['<?php echo ( $msg->get('Menu_Diferenca') ); ?>','index.php?opcao=derivada']
            ],
            ['<?php echo ( $msg->get('Menu_Integracao_Numerica') ); ?>','javascript:trees[0].toggle(41)',
                ['<?php echo ( $msg->get('Menu_Trapezio') ); ?>','index.php?opcao=intnum4'],
                ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Simpson')),ENT_QUOTES); ?>','index.php?opcao=intnum3'],
                ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Richardson')),ENT_QUOTES); ?>','index.php?opcao=intnum1'],
                ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Romberg')),ENT_QUOTES); ?>','index.php?opcao=intnum2']
            ]
        ],
        ['<?php echo ( $msg->get('Menu_EDO') ); ?>','javascript:trees[0].toggle(46)',
            ['<?php echo $msg->get('Menu_Euler'); ?>','index.php?inc=edo_euler.php'],
            ['<?php echo $msg->get('Menu_RungeKutta'); ?>','index.php?inc=edo_rungekutta.php']
        ]
    ]
];
new tree (TREE_ITEMS, TREE_TPL);
<?php
    }
    elseif ($_SESSION['ANAWEB']->RetornaModo() == "professor")
    {
?>
var TREE_ITEMS = [
    ['Na-Web', 'index.php',
        ['<?php echo $msg->get('Menu_Aritmetica_PF'); ?>','javascript:trees[0].toggle(1)',
            ['<?php echo $msg->get('Menu_Sistema_PF') ; ?>','index.php?opcao=gera_prob_ptoflut_sistema_xml'],
            ['<?php echo $msg->get('Menu_Soma') ; ?>','index.php?opcao=gera_prob_ptoflut_soma_xml'],
            ['<?php echo $msg->get('Menu_Multiplicacao') ; ?>','index.php?opcao=gera_prob_ptoflut_multiplicacao_xml'],
            ['<?php echo $msg->get('Menu_Divisao') ; ?>','index.php?opcao=gera_prob_ptoflut_divisao_xml'],
            ['<?php echo $msg->get('Menu_Subtracao') ; ?>','index.php?opcao=gera_prob_ptoflut_subtracao_xml']
        ],
        ['<?php echo $msg->get('Menu_Aritmetica_Matricial') ; ?>','javascript:trees[0].toggle(7)',
            ['<?php echo $msg->get('Menu_Multiplicacao') ; ?>','index.php?opcao=gera_prob_matriz_mul_xml'],
            ['<?php echo $msg->get('Menu_Soma') ; ?>','index.php?opcao=gera_prob_matriz_soma_xml'],
            ['<?php echo $msg->get('Menu_Transposta') ; ?>','index.php?opcao=gera_prob_matriz_transposta_xml']
        ],
        ['<?php echo $msg->get('Menu_SEAL') ; ?>','javascript:trees[0].toggle(11)',
            ['<?php echo $msg->get('Menu_Metodos_Diretos') ; ?>','index.php?opcao=seal_direto'],
            ['<?php echo $msg->get('Menu_Metodos_Iterativos') ; ?>','index.php?opcao=seal_iterativo']
        ],
        ['<?php echo $msg->get('Menu_Interpolacao') ; ?>','javascript:trees[0].toggle(14)',
            ['<?php echo $msg->get('Menu_Interpolacao') ; ?>','index.php?opcao=gera_interpolacao']
        ],
        ['<?php echo $msg->get('Menu_Ajuste_Dados') ; ?>','javascript:trees[0].toggle(16)',
            ['<?php echo $msg->get('Menu_Minimos_Quadrados') ; ?>','index.php?opcao=gera_prob_ajdados1_xml']
        ],
        ['<?php echo $msg->get('Menu_EQNL') ; ?>','javascript:trees[0].toggle(18)',
            //['<?php echo $msg->get('Menu_Bisseccao') ; ?>','index.php?opcao=gera_prob_eqnl2_xml'],
            //['<?php echo $msg->get('Menu_Secante') ; ?>','index.php?opcao=gera_prob_eqnl1_xml'],
            ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_EQNL2')),ENT_QUOTES) ; ?>','index.php?opcao=gera_prob_eqnl3_xml'],
            ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_EQNL2')),ENT_QUOTES)."(under development)" ; ?>','index.php?inc=gera_eqnl.php']
        ],
        ['<?php echo $msg->get('Menu_SEANL') ; ?>','javascript:trees[0].toggle(21)',
            ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Newton_SEANL')),ENT_QUOTES) ; ?>','index.php?opcao=gera_prob_seqnl_xml']
        ],
        ['<?php echo $msg->get('Menu_Integrais_Derivadas') ; ?>','javascript:trees[0].toggle(23)',
            ['<?php echo $msg->get('Menu_Derivacao') ; ?>','javascript:trees[0].toggle(24)',
                ['<?php echo $msg->get('Menu_Diferenca') ; ?>','index.php?opcao=gera_prob_derivada_xml']
            ],
            ['<?php echo $msg->get('Menu_Integracao_Numerica') ; ?>','javascript:trees[0].toggle(26)',
                ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Trapezio')),ENT_QUOTES) ; ?>','index.php?opcao=gera_prob_intnum4_xml'],
                ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Simpson')),ENT_QUOTES) ; ?>','index.php?opcao=gera_prob_intnum3_xml'],
                ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Richardson')),ENT_QUOTES) ; ?>','index.php?opcao=gera_prob_intnum1_xml'],
                ['<?php echo htmlentities(html_entity_decode($msg->get('Menu_Romberg')),ENT_QUOTES) ; ?>','index.php?opcao=gera_prob_intnum2_xml']
            ]
        ],
        ['<?php echo ( $msg->get('Menu_EDO') ); ?>','javascript:trees[0].toggle(31)',
            ['<?php echo $msg->get('Menu_Euler'); ?>','index.php?inc=edo_euler.php'],
            ['<?php echo $msg->get('Menu_RungeKutta'); ?>','index.php?inc=edo_rungekutta.php']
        ]
    ]
];
new tree (TREE_ITEMS, TREE_TPL);
<?php
        }
    }
    elseif ($_SESSION['ANAWEB']->RetornaAmbiente() == "scilab")
    {
        /*$xml_file = "./bibliotecas/scilab.xml";
        if ($_SESSION['ANAWEB']->RetornaModo() == "aluno")
        {
            $xml = DOMDOcument::load($xml_file);
            $expand = cas_domxml_createTree($xml,"scilab");
            echo "\nnew tree (TREE_ITEMS, TREE_TPL);";
            foreach ($expand as $a)
            {
                echo "\ntrees[0].toggle($a);";
            }
        }*/
        $xml_file = "./bibliotecas/scilab_valid.xml";
        $xml = DOMDOcument::load($xml_file);
        //$expand = cas_domxml_createTree($xml,"maple");
        echo "var TREE_ITEMS = [\n";
        echo "   ['Computer Algebra System', 'index.php'";
        $i=0;
        $k=0;
        $subject = $xml->getelementsbytagname("subject");
        foreach ($subject as $s) {
            $j=0;
            echo ",\n";
            $item = $s->getelementsbytagname("item");
            $name = $s->getAttribute("name");
            $k++;
            $expand[$i] = $k;
            echo "\n\t\t['$name',0";
            foreach ($item as $it) {
                echo ",\n";
                $name = $it->getAttribute("name");
                echo "\t\t\t['$name','index.php?inc=cas_load_system_scilab2.php&execucao=1&topico=$i&item=$j']";
                $j++;
                $k++;
            }
            echo "\n\t\t]";
            $i++;
        }
        echo "\n\t]\n]";
        echo "\nnew tree (TREE_ITEMS, TREE_TPL);";
        foreach ($expand as $a)
        {
            echo "\ntrees[0].toggle($a);";
        }
    }
    elseif ($_SESSION['ANAWEB']->RetornaAmbiente() == "maple")
    {
        /*
        $xml_file = "./bibliotecas/maple.xml";
        $xml = DOMDOcument::load($xml_file);
        $expand = cas_domxml_createTree($xml,"maple");
        echo "\nnew tree (TREE_ITEMS, TREE_TPL);";
        foreach ($expand as $a)
        {
            echo "\ntrees[0].toggle($a);";
        }*/
        $xml_file = "./bibliotecas/maple_valid.xml";
        $xml = DOMDOcument::load($xml_file);
        //$expand = cas_domxml_createTree($xml,"maple");
        echo "var TREE_ITEMS = [\n";
        echo "   ['Computer Algebra System', 'index.php'";
        $i=0;
        $k=0;
        $subject = $xml->getelementsbytagname("subject");
        foreach ($subject as $s) {
            $j=0;
            echo ",\n";
            $item = $s->getelementsbytagname("item");
            $name = $s->getAttribute("name");
            $k++;
            $expand[$i] = $k;
            echo "\n\t\t['$name',0";
            foreach ($item as $it) {
                echo ",\n";
                $name = $it->getAttribute("name");
                echo "\t\t\t['$name','index.php?inc=cas_load_system_maple2.php&execucao=1&topico=$i&item=$j']";
                $j++;
                $k++;
            }
            echo "\n\t\t]";
            $i++;
        }
        echo "\n\t]\n]";
        echo "\nnew tree (TREE_ITEMS, TREE_TPL);";
        foreach ($expand as $a)
        {
            echo "\ntrees[0].toggle($a);";
        }
    }
    function cas_domxml_createTree($root,$amb) {
        $subject = $root -> getelementsbytagname("subject");
        init_jsTree();
        $i=0;
        $j=1;
        foreach ($subject as $s) {
                echo ",\n";
            $item = $s -> getelementsbytagname("item");
            $name = $s->getAttribute("name");
            $expand[$i++] = $j++;
            $j = add_jsSubj($name, $item, $amb,$j);
        }
        close_jsTree();
        return $expand;
    }
    function init_jsTree() {
echo "var TREE_ITEMS = [\n";
echo "   ['Computer Algebra System', 'index.php'";
    }
    
    // codigo de encerramento da arvore
    function close_jsTree() {
echo "\n\t]\n]";
    }
    
    // adiciona assuntos bem como seus items correspondentes como links
    function add_jsSubj($sub_name, $item, $amb,$j) {
        //echo "\t\t subject = new WebFXTreeItem(\"&nbsp ".$sub_name."\"); \n";
        echo "\n\t\t['$sub_name',0";
        foreach ($item as $i) {
            $j++;
            echo ",\n";
            $name = $i->getAttribute("name");

            $description = $i -> getelementsbytagname("description");

            $commands = $i -> getelementsbytagname("commands");
            $command = $commands->item(0)->getelementsbytagname("command");

            $tryyourself = $i -> getelementsbytagname("try_yourself");
            $try = $tryyourself->item(0)->getelementsbytagname("try");

            $examples = $i -> getelementsbytagname("examples");
            $example = $examples->item(0)->getelementsbytagname("example");
            $params = "";
            $params = $description->item(0)->nodeValue."[.d.]";

            /*foreach ($command as $c) {
                $params .= "[.c.]".$c->nodeValue;
            }
            foreach ($try as $t) {
                $params .= "[.t.]".$t->nodeValue;
            }*/
            foreach ($example as $e) {
                $params .= "[.e.]".$e->nodeValue;
            }
            //echo "params: ".$cas_parameters."<br>";
            $params = base64_encode($params);
            $title = base64_encode($name);

            if ($amb == "scilab") echo "\t\t\t['$name','index.php?opcao=cas_load_system_scilab&title=$title&param=$params']";
            elseif ($amb == "maple") echo "\t\t\t['$name','index.php?opcao=cas_load_system_maple&title=$title&param=$params']";
        }
        echo "\n\t\t]";
        return $j;
    }
?>
